package com.emily.mall.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.emily.mall.order.fegin.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.emily.mall.order.entity.OrderEntity;
import com.emily.mall.order.service.OrderService;
import com.emily.common.utils.PageUtils;
import com.emily.common.utils.R;



/**
 * 订单
 *
 * @author yjhou
 * @email yjhou198714@163.com
 * @date 2025-02-14 23:11:21
 *   @RefreshScope：实现Nacos配置文件的动态刷新，不能配置在启动类上，无效果，作用域是：ElementType.TYPE, ElementType.METHOD
 */

@RefreshScope
@RestController
@RequestMapping("order/order")
public class OrderController {
    private static final Logger log = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    private OrderService orderService;

    @Autowired
    private ProductService productService;

    @GetMapping("/products")
    public R  queryProductList(){
        return R.ok().put("products",productService.queryAllBrand());
    }


    //获取配置信息
    @Value("${user.userName}")
    private String userName;
    @Value("${user.age}")
    private String age;


    @GetMapping("/users")
    public R  queryUserList(){
        return R.ok().put("userName",userName).put("age",age);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);
        log.info("查询所有订单列表-----------------");
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
